package com.ruoyi.kong.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.kong.controller.vo.GroupAddUsersVo;
import com.ruoyi.kong.mapper.dto.KGroupDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kong.domain.KGroup;
import com.ruoyi.kong.service.IKGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备组Controller
 * 
 * @author zeroUp
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/kong/group")
public class KGroupController extends BaseController
{
    @Autowired
    private IKGroupService kGroupService;

    /**
     * 查询设备组列表
     */
    @PreAuthorize("@ss.hasPermi('kong:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(KGroup kGroup)
    {
        startPage();
        kGroup.setCreateBy(SecurityUtils.getUserId().toString());
        List<KGroupDto> list = kGroupService.selectKGroupList(kGroup);
        return getDataTable(list);
    }


    @PostMapping("/listAll")
    public AjaxResult list(String keyWord)
    {
        List<KGroupDto> list = kGroupService.listAll(keyWord);
        return AjaxResult.success(list);
    }

    /**
     * 导出设备组列表
     */
    @PreAuthorize("@ss.hasPermi('kong:group:export')")
    @Log(title = "设备组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KGroup kGroup)
    {
        List<KGroupDto> list = kGroupService.selectKGroupList(kGroup);
        ExcelUtil<KGroupDto> util = new ExcelUtil<KGroupDto>(KGroupDto.class);
        util.exportExcel(response, list, "设备组数据");
    }

    /**
     * 获取设备组详细信息
     */
    @PreAuthorize("@ss.hasPermi('kong:group:query')")
    @GetMapping(value = "/{gid}")
    public AjaxResult getInfo(@PathVariable("gid") Long gid)
    {
        return success(kGroupService.selectKGroupByGid(gid));
    }

    /**
     * 新增设备组
     */
    @PreAuthorize("@ss.hasPermi('kong:group:add')")
    @Log(title = "设备组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KGroup kGroup)
    {
        kGroup.setCreateBy(SecurityUtils.getUserId().toString());
        return toAjax(kGroupService.insertKGroup(kGroup));
    }

    /**
     * 修改设备组
     */
    @PreAuthorize("@ss.hasPermi('kong:group:edit')")
    @Log(title = "设备组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KGroup kGroup)
    {
        return toAjax(kGroupService.updateKGroup(kGroup));
    }

    /**
     * 删除设备组
     */
    @PreAuthorize("@ss.hasPermi('kong:group:remove')")
    @Log(title = "设备组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gids}")
    public AjaxResult remove(@PathVariable Long[] gids)
    {
        return toAjax(kGroupService.deleteKGroupByGids(gids));
    }



}
